package cn.com.gzheroli.core.util;

import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Transient;

import org.apache.ibatis.jdbc.SQL;
import org.beetl.sql.core.annotatoin.ColumnIgnore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.gzheroli.core.common.entity.TableAndColumns;
import cn.com.gzheroli.core.common.model.common.SqlContext;

public class MyBatisSqlUtils {
	/** 日志对象 */
	private static final Logger LOG = LoggerFactory.getLogger(MyBatisSqlUtils.class);

	/**
	 * 构建insert语句
	 *
	 * @param entity
	 *            实体映射对象
	 * @param nameHandler
	 *            名称转换处理器
	 * @return
	 */
	public static Map<String, Object> buildInsertSql(Object entity, Map<String,Object> tableColumns,
			Class... parentClassName) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		Map<String, Object> paraMap = new HashMap<String, Object>();
		String className = "";
		Class<?> clazz = entity.getClass();
		className = clazz.getSimpleName();
		if (parentClassName != null && parentClassName.length == 1) {
			className = parentClassName[0].getSimpleName();
			clazz=parentClassName[0];
		}
		String tableName = className;
		if (!className.contains("_")) {
			tableName = NameHandler.getTableName(className);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		MyBeanUtils.copyBean2Map(map, entity);
		StringBuilder sql = new StringBuilder("insert into ");
		List<Object> params = new ArrayList<Object>();
		sql.append(tableName);
		SQL mySql = new SQL();
		mySql.INSERT_INTO(tableName);
		Field[] fields = clazz.getDeclaredFields();
		for (Field f : fields) {
			String filedName = f.getName(); // org.beetl.sql.core.annotatoin.ColumnIgnore
			String key = filedName;
			// System.out.println("属性名称:【"+filedName+"】"); //javax.persistence.Transient
			// 1、获取属性上的指定类型的注解
			Transient annotation = f.getAnnotation(Transient.class);
			// 有该类型的注解存在
			if (annotation != null) {
				continue;
			}
			Object value = map.get(key);
			if (key.equalsIgnoreCase("id") && (value == null || value.toString().trim().equals(""))) {
				value = IdWorker.getFlowIdWorkerInstance().nextIdStr();
			}
			if (value == null) {
				continue;
			}
			String columnName = NameHandler.getColumnName(key);
			columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
			if (tableColumns != null && !tableColumns.isEmpty()&&!columnName.equals("")) {
				/*if (tableColumns.contains(columnName)) {
					mySql.INTO_COLUMNS(columnName);
				} else if (tableColumns.contains(columnName + "_")) {
					mySql.INTO_COLUMNS(columnName + "_");
				} else {
					continue;
				}*/
				mySql.INTO_COLUMNS(columnName);
			} else {
				Column cAnnotation = f.getAnnotation(Column.class);
				if (cAnnotation != null) {
					columnName = cAnnotation.name();
					
					mySql.INTO_COLUMNS(columnName);
				} else {
					if (tableName.startsWith("ACT_")) {
						columnName = columnName + "_";
					}
					mySql.INTO_COLUMNS(columnName);
				}
			}
			mySql.INTO_VALUES("#{" + key + "}");
			paraMap.put(key, value);
		}
		sqlMap.put("sql", mySql.toString());
		sqlMap.putAll(paraMap);
		return sqlMap;
	}

	/**
	 * 构建更新sql
	 * 
	 * @param entity
	 * @param nameHandler
	 * @return
	 */
	public static Map<String, Object> buildUpdateSql(Object entity, Map<String,Object> tableColumns,
			Class... parentClassName) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		Map<String, Object> paraMap = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		MyBeanUtils.copyBean2Map(map, entity);
		String className = "";
		Class<?> clazz = entity.getClass();
		className = clazz.getSimpleName();
		if (parentClassName != null && parentClassName.length == 1) {
			className = parentClassName[0].getSimpleName();
			clazz=parentClassName[0];
		}
		String tableName = className;
		if (!className.contains("_")) {
			tableName = NameHandler.getTableName(className);
		}
		SQL sql = new SQL();
		sql.UPDATE(tableName);
		List<Object> params = new ArrayList<Object>();
		String primaryName = NameHandler.getPrimaryName(clazz.getSimpleName());
		primaryName = "id";
		/*if (tableColumns.contains(primaryName)) {
			primaryName = primaryName;
		} else if (tableColumns.contains(primaryName + "_")) {
			primaryName = primaryName + "_";
		}*/
		primaryName = tableColumns.get(primaryName)==null?"ID":tableColumns.get(primaryName).toString();
		Object primaryValue = null;
		// for (String key : map.keySet()) {
		Field[] fields = clazz.getDeclaredFields();
		for (Field f : fields) {
			String filedName = f.getName(); // org.beetl.sql.core.annotatoin.ColumnIgnore
			String key = filedName;
			// System.out.println("属性名称:【"+filedName+"】"); //javax.persistence.Transient
			// 1、获取属性上的指定类型的注解
			Transient annotation = f.getAnnotation(Transient.class);
			// 有该类型的注解存在
			if (annotation != null) {
				continue;
			}
			Object value = map.get(key);
			if (key.equalsIgnoreCase("id")) {
				primaryValue = value;
			}
			if (value == null) {
				continue;
			}
			String columnName = NameHandler.getColumnName(key);
			columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
			if (primaryName.equalsIgnoreCase(columnName)) {
				primaryValue = value;
			}
			paraMap.put(key, value);
			if (!columnName.equals("")) {
				
				sql.SET(columnName + "=#{" + key + "}");
			} else {
				Column cAnnotation = f.getAnnotation(Column.class);
				if (cAnnotation != null) {
					columnName = cAnnotation.name();
					/*if (tableName.startsWith("ACT_")) {
						columnName = columnName + "_";
					}*/
					sql.SET(columnName + "=#{" + key + "}");
				} else {
					if (tableName.startsWith("ACT_")) {
						columnName = columnName + "_";
					}
					if(!columnName.equals("")) {
						sql.SET(columnName + "=#{" + key + "}");
					}
				}
			}
			continue;
		}
		sql.WHERE(primaryName + "=#{id}");
		paraMap.put("id", primaryValue);
		sqlMap.put("sql", sql.toString());
		sqlMap.putAll(paraMap);
		return sqlMap;
	}

	/**
	 * 
	 * @Title: buildBeetlInsertSql @Description: 构建insert语句 @param @param
	 * tableName @param @param paras @param @return 设定文件 @return Map<String,Object>
	 * 返回类型 @throws
	 */
	public static Map<String, Object> buildBeetlInsertSql(String tableName, Map<String, Object> paras) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		SQL sql = new SQL();
		if (tableName.indexOf("_") < 0) {
			tableName = NameHandler.getTableName(tableName);
		}
		sql.INSERT_INTO(tableName);
		if (!paras.containsKey("id") || !paras.containsKey("id_")) {
			String key = "id";
			String columnName = NameHandler.getColumnName(key);
			if (tableName.startsWith("Act") && !columnName.endsWith("_")) {
				columnName = NameHandler.getColumnName(key + "_");
			}
			sql.INTO_VALUES("#" + key + "#");
			sql.INTO_COLUMNS(columnName);
			sqlMap.put(key, IdWorker.getFlowIdWorkerInstance().nextIdStr());
		}

		for (String key : paras.keySet()) {
			Object value = paras.get(key);
			if ((key.equalsIgnoreCase("id") || key.equalsIgnoreCase("id_"))
					&& (value == null || value.toString().trim().equals(""))) {
				value = IdWorker.getFlowIdWorkerInstance().nextIdStr();
			}
			if (value == null) {
				continue;
			}
			String columnName = NameHandler.getColumnName(key);
			if (tableName.startsWith("Act") && !columnName.endsWith("_")) {
				columnName = NameHandler.getColumnName(key + "_");
			}
			sql.INTO_VALUES("#" + key + "#");
			sql.INTO_COLUMNS(columnName);
			sqlMap.put(key, value);
		}
		sqlMap.put("sql", sql.toString());
		return sqlMap;
	}

	/**
	 * 构建更新sql
	 * 
	 * @param entity
	 * @param nameHandler
	 * @return
	 */
	public static Map<String, Object> buildBeetlUpdateSql(String tableName, Map<String, Object> paras,
			Map<String, Object> whereMap) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		Map<String, Object> paraMap = new HashMap<String, Object>();
		SQL sql = new SQL();
		if (tableName.indexOf("_") < 0) {
			tableName = NameHandler.getTableName(tableName);
		}
		sql.UPDATE(tableName);
		for (String key : paras.keySet()) {
			Object value = paras.get(key);
			if (value == null) {
				continue;
			}
			String columnName = NameHandler.getColumnName(key);
			if (tableName.startsWith("Act") && !columnName.endsWith("_")) {
				columnName = NameHandler.getColumnName(key + "_");
			}
			sql.SET(columnName + "=#" + key + "#");
			paraMap.put(key, value);
		}
		if (whereMap != null && !whereMap.isEmpty()) {
			for (String key : whereMap.keySet()) {

				String columnName = NameHandler.getColumnName(key);
				if (tableName.startsWith("Act") && !columnName.endsWith("_")) {
					columnName = NameHandler.getColumnName(key + "_");
				}
				sql.WHERE(columnName + "=#" + key + "#");
				Object value = whereMap.get(key);
				paraMap.put(key.toString(), value);
			}
		} else {
			String columnName = NameHandler.getColumnName("id");
			if (tableName.startsWith("Act") && !columnName.endsWith("_")) {
				columnName = NameHandler.getColumnName("id" + "_");
			}
			sql.WHERE(columnName + "=#id#");
			paraMap.put("id", paraMap.get("id") == null ? paraMap.get("id") : paraMap.get("id_"));
		}

		sqlMap.put("sql", sql.toString());
		sqlMap.putAll(paraMap);
		// sqlMap.put("paraMap", paraMap);
		return sqlMap;
	}

	/**
	 * 
	 * @Title: buildBeetlDeleteSql @Description: 删除语句生成 @param @param
	 * tableName @param @param whereMap @param @return 设定文件 @return
	 * Map<String,Object> 返回类型 @throws
	 */
	public static Map<String, Object> buildBeetlDeleteSql(String tableName, Map<String, Object> whereMap) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		SQL sql = new SQL();
		if (tableName.indexOf("_") < 0) {
			tableName = NameHandler.getTableName(tableName);
		}
		sql.DELETE_FROM(tableName);
		if (whereMap != null && !whereMap.isEmpty()) {
			for (String key : whereMap.keySet()) {

				String columnName = NameHandler.getColumnName(key);
				if (tableName.startsWith("Act") && !columnName.endsWith("_")) {
					columnName = NameHandler.getColumnName(key + "_");
				}
				sql.WHERE(columnName + "=#" + key + "#");
				Object value = whereMap.get(key);
				sqlMap.put(key.toString(), value);
			}
			sqlMap.put("sql", sql.toString());
			return sqlMap;
		} else {
			sqlMap.put("sql", "");
			return sqlMap;
		}
	}

	/**
	 * 获取属性值
	 *
	 * @param readMethod
	 * @param entity
	 * @return
	 */
	private static Object getReadMethodValue(Method readMethod, Object entity) {
		if (readMethod == null) {
			return null;
		}
		try {
			if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
				readMethod.setAccessible(true);
			}
			return readMethod.invoke(entity);
		} catch (Exception e) {
			LOG.error("获取属性值失败", e);
			throw new RuntimeException(e);
		}
	}

	/**
	 * 构建insert语句
	 *
	 * @param entity
	 *            实体映射对象
	 * @param nameHandler
	 *            名称转换处理器
	 * @return
	 */
	public static Map<String, Object> buildInsertSql(Object entity, String tableName) {
		return buildInsertSql(entity, tableName, "mybatis");
	}

	/**
	 * 构建更新sql
	 * 
	 * @param entity
	 * @param nameHandler
	 * @return
	 */
	public static Map<String, Object> buildUpdateSql(Object entity, String tableName, Map<String, Object> where) {
		return buildUpdatetSql(entity, tableName, where, "mybatis");
	}

	/**
	 * 构建insert语句
	 *
	 * @param entity
	 *            实体映射对象
	 * @param nameHandler
	 *            名称转换处理器
	 * @return
	 */
	public static Map<String, Object> buildBeetlInsertSql(Object entity, String tableName) {
		return buildInsertSql(entity, tableName, "beetlsql");
	}

	/**
	 * 构建更新sql
	 * 
	 * @param entity
	 * @param nameHandler
	 * @return
	 */
	public static Map<String, Object> buildBeetlUpdateSql(Object entity, String tableName, Map<String, Object> where) {
		return buildUpdatetSql(entity, tableName, where, "beetlsql");
	}

	private static Map buildInsertSql(Object entity, String tableName, String type) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		Map<String, Object> paraMap = new HashMap<String, Object>();
		String className = "";
		Class<?> clazz = entity.getClass();
		className = clazz.getSimpleName();
		Map<String,Object> tableColumns=getTableColumns(clazz);
		if (!tableName.contains("_")) {
			tableName = NameHandler.getTableName(className);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		MyBeanUtils.copyBean2Map(map, entity);
		List<Object> params = new ArrayList<Object>();
		SQL sql = new SQL();
		sql.INSERT_INTO(tableName);
		Field[] fields = clazz.getDeclaredFields();
		for (Field f : fields) {
			String filedName = f.getName(); // org.beetl.sql.core.annotatoin.ColumnIgnore
			String key = filedName;
			// System.out.println("属性名称:【"+filedName+"】"); //javax.persistence.Transient
			// 1、获取属性上的指定类型的注解
			Transient annotation = f.getAnnotation(Transient.class);
			// 有该类型的注解存在
			if (annotation != null) {
				continue;
			}
			Object value = map.get(key);
			if (key.equalsIgnoreCase("id") && (value == null || value.toString().trim().equals(""))) {
				value = IdWorker.getFlowIdWorkerInstance().nextIdStr();
			}
			if (value == null) {
				continue;
			}
			String columnName = NameHandler.getColumnName(key);
			columnName=tableColumns.get(key)==null?"":tableColumns.get(key).toString();
			if(columnName.equals(""))
				continue;
			Column cAnnotation = f.getAnnotation(Column.class);
			if (cAnnotation != null) {
				columnName = cAnnotation.name();
				sql.INTO_COLUMNS(columnName);
			} else {
				sql.INTO_COLUMNS(columnName);
			}
			if (type.equals("beetlsql")) {
				sql.INTO_VALUES("#" + key + "#");
			} else {
				sql.INTO_VALUES("#{" + key + "}");
			}
			paraMap.put(key, value);
		}
		if (sql.toString().indexOf("()") > -1) {
			sqlMap.put("sql", "");
			sqlMap.put("paraMap", new HashMap());
			return sqlMap;
		}
		sqlMap.put("sql", sql.toString());
		sqlMap.putAll(paraMap);
		return sqlMap;
	}

	private static Map buildUpdatetSql(Object entity, String tableName, Map<String, Object> where, String type) {
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		Map<String, Object> paraMap = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		MyBeanUtils.copyBean2Map(map, entity);
		String className = "";
		Class<?> clazz = entity.getClass();
		className = clazz.getSimpleName();
		Map<String,Object> tableColumns=getTableColumns(clazz);
		if (!tableName.contains("_")) {
			tableName = NameHandler.getTableName(className);
		}
		List<Object> params = new ArrayList<Object>();
		String primaryName = NameHandler.getPrimaryName(clazz.getSimpleName());
		primaryName = "ID";
		Object primaryValue = null;
		SQL sql = new SQL();
		sql.UPDATE(tableName);
		Field[] fields = clazz.getDeclaredFields();
		for (Field f : fields) {
			String filedName = f.getName();
			String key = filedName;
			// System.out.println("属性名称:【"+filedName+"】");
			Object value = map.get(key);
			if (key.equalsIgnoreCase("id")) {
				primaryValue = value;
			}
			if (value == null) {
				continue;
			}
			String columnName = NameHandler.getColumnName(key);
			columnName=tableColumns.get(key)==null?"":tableColumns.get(key).toString();
			if(columnName.equals(""))
				continue;
			if (primaryName.equalsIgnoreCase(columnName)) {
				primaryValue = value;
			}
			paraMap.put(key, value);
			Column cAnnotation = f.getAnnotation(Column.class);
			if (cAnnotation != null) {
				columnName = cAnnotation.name();
				/*if (tableName.startsWith("ACT_")) {
					columnName = columnName + "_";
				}*/
				
				if (type.equals("beetlsql")) {
					sql.SET(columnName + "=" + "#" + key + "#");
				} else {
					sql.SET(columnName + "=" + "#{" + key + "}");
				}
			} else {
				if (type.equals("beetlsql")) {
					sql.SET(columnName + "=" + "#" + key + "#");
				} else {
					sql.SET(columnName + "=" + "#{" + key + "}");
				}
			}
		}
		if (where != null && !where.isEmpty()) {
			for (String key : where.keySet()) {
				Object value = where.get(key);
				String columnName = NameHandler.getColumnName(key);
				columnName=tableColumns.get(key)==null?"":tableColumns.get(key).toString();
				if(columnName.equals(""))
					continue;
				if (key.contains("_")) {
					columnName = key;
				}
				if (type.equals("beetlsql")) {
					sql.WHERE(columnName + "=" + "#" + key + "#");
				} else {
					sql.WHERE(columnName + "=" + "#{" + key + "}");
				}
				paraMap.put(key, where.get(key));
			}
		} else {
			if (type.equals("beetlsql")) {
				sql.WHERE("ID=#id#");
			} else {
				sql.WHERE("ID=#{id}");
			}
			paraMap.put("id", primaryValue);
		}
		sqlMap.put("sql", sql.toString());
		sqlMap.putAll(paraMap);
		return sqlMap;
	}
    /**
     * 构建insert语句
     *
     * @param entity 实体映射对象
     * @param nameHandler 名称转换处理器
     * @return
     */
    public static Map<String,Object> buildInsertSql(Object entity,Map<String,Object> tableColumns,String parentClassName) {
	    	Map<String,Object> sqlMap=new HashMap<String,Object>();
	    	String className="";
	    	SQL sql=new SQL();
        Class<?> clazz = entity.getClass();
        className=clazz.getSimpleName();
        if(parentClassName != null && !parentClassName.trim().equals(""))
    			className=parentClassName;
        String tableName =className;
        if(!className.contains("_"))
        		tableName=NameHandler.getTableName(className);
        //String primaryName = nameHandler.getPrimaryName(clazz.getSimpleName());
        Map<String,Object> map=new HashMap<String,Object>();
    		MyBeanUtils.copyBean2Map(map, entity);
    		sql.INSERT_INTO(tableName);
        if(!map.containsKey("id")||!map.containsKey("id_")){
	        	String key="id";
	        //	String columnName=NameHandler.getColumnName(key);
	        	String 	columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
            /*if(tableName.startsWith("Act")&&!columnName.endsWith("_"))
            	columnName=NameHandler.getColumnName(key+"_");*/
            sql.INTO_VALUES("#{"+key+"}");
	        	sql.INTO_COLUMNS(columnName);
	        	sqlMap.put(key, IdWorker.getFlowIdWorkerInstance().nextIdStr());
        }
        	
        for (String key : map.keySet()) {  
            Object value =map.get(key);
            if((key.equalsIgnoreCase("id")||key.equalsIgnoreCase("id_"))&&(value == null||value.toString().trim().equals("")))
					value=IdWorker.getFlowIdWorkerInstance().nextIdStr();
            if (value == null) {
                continue;
            }
            //String columnName=NameHandler.getColumnName(key);
            String columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
            /*if(tableName.startsWith("Act")&&!columnName.endsWith("_"))
            		columnName=NameHandler.getColumnName(key+"_");
            if(tableColumns.contains(columnName+"_")) {
            		columnName=columnName+"_";
            }
            if(tableColumns.contains(columnName)) {
            		sql.INTO_VALUES("#{"+key+"}");
                sql.INTO_COLUMNS(columnName);
            }*/
            if(!columnName.equals("")) {
            		sql.INTO_VALUES("#{"+key+"}");
                sql.INTO_COLUMNS(columnName);
            }
        		sqlMap.put(key, value);
        }
        sqlMap.put("sql", sql.toString());
        return sqlMap;
    }
    public static Map<String,Object> buildUpdateSql(Object entity,Map<String,Object> tableColumns,String parentClassName,Map<String,Object> whereMap) {
    	Map<String,Object> sqlMap=new HashMap<String,Object>();
    	Map<String,Object> paraMap=new HashMap<String,Object>();
    	Map<String,Object> map=new HashMap<String,Object>();
    	MyBeanUtils.copyBean2Map(map, entity);
    	SQL sql=new SQL();
    	String primaryName = NameHandler.getPrimaryName(entity.getClass().getSimpleName());
    primaryName="ID";
    	String className="";
    Class<?> clazz = entity.getClass();
    className=clazz.getSimpleName();
    if(parentClassName != null && !parentClassName.trim().equals("")) {
    		className=parentClassName;
    }
    String tableName =className;
    if(!className.contains("_")) {
    		tableName=NameHandler.getTableName(className); 
    }
    if(tableName.indexOf("_")<0) {
    		tableName=NameHandler.getTableName(tableName);
    }
    sql.UPDATE(tableName);
    for (String key : map.keySet()) { 
    		Object value =map.get(key);
        if (value == null) {
            continue;
        }
        //String columnName=NameHandler.getColumnName(key);
        String columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
        /*if(tableName.startsWith("Act")&&!columnName.endsWith("_")) {
        	columnName=NameHandler.getColumnName(key+"_");
        }
        if(tableColumns.contains(columnName+"_")) {
    			columnName=columnName+"_";
	    }
	    if(tableColumns.contains(columnName)) {
	        sql.SET(columnName+"=#{"+key+"}");
	        paraMap.put(key, value);
	    }*/
	    if(!columnName.equals("")) {
	    		sql.SET(columnName+"=#{"+key+"}");
	        paraMap.put(key, value);
	    }
    }
    if(whereMap!=null&&!whereMap.isEmpty()){
    	for (String key : whereMap.keySet()) { 
    		
    		//String columnName=NameHandler.getColumnName(key);
            /*if(tableName.startsWith("Act")&&!columnName.endsWith("_")) {
            	columnName=NameHandler.getColumnName(key+"_");
            }*/
    			String columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
            sql.WHERE(columnName+"=#{"+key+"}");
    			Object value =whereMap.get(key);
            paraMap.put(key.toString(), value);
        }
    }else{
    		String columnName=NameHandler.getColumnName("id");
        /*if(tableName.startsWith("Act")&&!columnName.endsWith("_")) {
        		columnName=NameHandler.getColumnName("id"+"_");
        }*/
        String key="id";
        columnName = tableColumns.get(key)==null?"":tableColumns.get(key).toString();
        sql.WHERE(columnName+"=#{id}");
        paraMap.put("id", paraMap.get("id")==null?paraMap.get("id"):paraMap.get("id_"));
    }
    sqlMap.put("sql", sql.toString());
    sqlMap.putAll(paraMap);
    return sqlMap;
    }
	public static Map<String, Object> getTableColumns(Class obj) {
		Field[] fields = obj.getDeclaredFields();
		Map<String, Object> fieldNames = new HashMap<String, Object>();
		for (int i = 0; i < fields.length; i++) {
			System.out.println(fields[i].getType());
			Field f = fields[i];
			Transient annotation = f.getAnnotation(Transient.class);
			// 有该类型的注解存在
			if (annotation != null) {
				continue;
			}
			Column cAnnotation = f.getAnnotation(Column.class);
			if (cAnnotation != null) {
				fieldNames.put(f.getName(), cAnnotation.name());
			} else {
				fieldNames.put(f.getName(), NameHandler.getColumnName(f.getName()));
			}
		}
		return fieldNames;
	}
}
